<?php

//
// +------------------------------------------------------------------------+
// | PHP Version 5.4                                                        |
// +------------------------------------------------------------------------+
// | Copyright (c) All rights reserved.                                     |
// +------------------------------------------------------------------------+
// | 世纪车来车往(北京）网络科技有限公司 版权所有！                               |
// | TEL:010-63732365  HOTLINE:400-6688-365  EMAIL:clcw@clcw.com.cn         |
// | $Revision: 1.0 $                                                       |
// +------------------------------------------------------------------------+
// | Author: liguohua@clcw.com.cn                                        |
// +------------------------------------------------------------------------+
//

namespace AuctionCore\Other;
use AuctionCore\Account\Back\Employee;
use AuctionCore\System\AuctionException;

/**
 * 门店列表
 * @author Eric
 */
class Store {

    public $store = null;
    public $store_pic = null;

    public function __construct(){
         $this->store = M('store');
        $this->store_pic = M('store_pics');
    }
    public function index(){

    }

    //新增门店或门店照片
    public function add($data,$table='store'){
        $data['lasttime'] = date('Y-m-d H:i:s');
        $rs = M($table)->add($data);
        return $rs;
    }

    //更新门店或门店照片
    public function update($data,$map=array(),$table='store'){
        $data['lasttime'] = date('Y-m-d H:i:s');
        $rs = M($table)->where($map)->save($data);
        return $rs;

    }

    //获取门店详情
    public function detail($map=array()){
        return M('store')->where($map)->find();
    }

    //获取所有门店
    public function get_stores($map=array()){
            $arr = array();
            $ret = M('store')->where($map)->select();
            foreach($ret as $v){
                $arr[$v['store_id']] = $v['store_name'];
            }
            return $arr;
    }

    /**
     * 获取门店下员工
     * @param $params
     * @return bool|mixed
     */
    public function get_store_emp_by_store_group($store_id, $group_id = 0)
    {
        if ($store_id < 1) return false;
        $store = $this->detail(['store_id' => $store_id,'status'=>0]);
        $map = array();
        $map['e.status'] = ['eq', 0];
        $map['e.depart_id'] = ['eq', $store['depart_id']];
        if ($group_id > 0) {
            $map['g.id'] = ['eq', $group_id];
        }
        $prefix = C('DB_PREFIX');
        $list = M('employee')->alias("e")->field("e.emp_id,e.real_name")
            ->join("{$prefix}emp_group_access g ON e.emp_id = g.emp_id")
            ->where($map)->select();
        //echo M()->getLastSql();
        return $list;
    }

}
